from app.extensions import db
from datetime import datetime


class PointRecord(db.Model):
    __tablename__ = 'point_records'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)  # 主键
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)  # 用户ID
    points = db.Column(db.Integer, nullable=False, default=0)  # 积分数
    type = db.Column(db.String(50), nullable=False)  # 积分类型（答题、上传图片、每日签到等）
    created_at = db.Column(db.DateTime, default=datetime.utcnow)  # 获得时间

    user = db.relationship("User", backref="point_records")  # 方便反查
